package com.rem.rabbitmq.ee.HdeadLetterQueue;

import com.rabbitmq.client.CancelCallback;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import com.rem.rabbitmq.ee.RabbitMqUtils;


/**
 * 死信消费者
 *
 * @author Rem
 * @date 2021-12-27
 */

public class ConsumerDead16 {

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();

        //声明死信交换机
       // channel.exchangeDeclare(RabbitMqUtils.EXCHANGE_DEAD, BuiltinExchangeType.DIRECT);
        //声明死信队列
       // channel.queueDeclare(RabbitMqUtils.QUEUE_DEAD, false, false, false, null);
        //死信队列绑定死信交换机与routingkey
       // channel.queueBind(RabbitMqUtils.QUEUE_DEAD, RabbitMqUtils.EXCHANGE_DEAD, RabbitMqUtils.ROUTING_KEY_DEAD);

        //消费回调
        DeliverCallback deliverCallback = (consumerTag, message) -> System.out.println("接收到的死信消息：" + new String(message.getBody()));

        //取消消费回调 如果在消费的时候队列被删除了
        CancelCallback cancelCallback = consumerTag -> System.out.println("消费消息被中断");

        System.out.println("消费者-DEAD 等待消费");
        channel.basicConsume(RabbitMqUtils.QUEUE_DEAD, true, deliverCallback, cancelCallback);
    }


}
